//
//  LRMainViewController.swift
//  LRWeibo
//  分钟第放得开就发达较高的世界观发大水了广东省打开该是多么高大上管理爱的覅
//  Created by admin on 15/9/21.
//  Copyright © 2015年 懒人. All rights reserved.
//print("测试 ", appendNewLine: false)

/**collectionView--》cell
行高计算  动态随机测试items数量
*/

import UIKit

class LRMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        // 添加控制器
        addChildViewControllers()
        
        // 添加撰写按钮
        setComposeButton()
        
    }

    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        tabBar.bringSubviewToFront(composeButton)

    }
    
     // MARK: - 设置撰写按钮
    private func setComposeButton(){
        
        tabBar.addSubview(composeButton)
        composeButton.addTarget(self, action: "composeButtonClick", forControlEvents: .TouchUpInside)
        let count = childViewControllers.count
        let w = tabBar.bounds.width / CGFloat(count) - 1
        composeButton.frame = CGRectInset(tabBar.bounds, 2 * w, 0)
        
    }
    
    @objc private func composeButtonClick()
    {
        print("ff")
    }
    
     // MARK: - 添加控制器
    private func addChildViewControllers()
    {
        addChildViewController("首页", vc: LRHomeViewController(), imageName: "tabbar_home")
        addChildViewController("消息", vc: LRMessageViewController(), imageName: "tabbar_message_center")
        addChildViewController(ViewController())
        addChildViewController("发现", vc: LRDiscoverViewController(), imageName: "tabbar_discover")
        addChildViewController("个人", vc: LRProfileViewController(), imageName: "tabbar_profile")
        
    }
    
    private func addChildViewController(title: String, vc:UIViewController, imageName: String){

        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.navigationController?.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }

     // MARK: - 控件懒加载 
    private lazy var composeButton:UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
}
